﻿using BusinessLayer.DatabaseEntities;
using BusinessLayer.VDataEntities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BusinessLayer
{
    public class PromoterBusiness
    {
        //验证用户名
        public static VPromoter ValidatePromoter(string name, long clientID, string openid = null)
        {

            using (CustomerServiceCenterEntities entities = new CustomerServiceCenterEntities())
            {
                var validatedPromoter = from promoter in entities.EndUser
                                        where (promoter.UserName == name)
                                        && (promoter.ClientID == clientID)
                                        && (promoter.IsActive == true)
                                        && (openid == null ? true : promoter.openid == openid)
                                        select new VPromoter() { ChineseName = promoter.UserName, Name = promoter.UserName, IsActive = true, ID = promoter.ID, ClientID = promoter.ClientID };
                return validatedPromoter.FirstOrDefault();
            }
        }
        /// <summary>
        /// 添加用户
        /// </summary>
        /// <param name="user"></param>
        public static void AddPromoter(VEndUser user)
        {
            using (CustomerServiceCenterEntities entities = new CustomerServiceCenterEntities())
            {
                EndUser enduser = new EndUser{
                    ClientID = user.ClientID,
                    IsActive = true,
                    UserName = user.Name,

                    //服务号
                    //openid = user.openid,
                };
                entities.EndUser.Add(enduser);
                entities.SaveChanges();
            }
        }


    }
}
